package net.cyndeline.GameMap.dataStructure

import net.cyndeline.entitySystem.EntityRef
import net.cyndeline.GameMap.Tile
import com.escalatesoft.subcut.inject.BindingModule


/**
 * A single container on a hex grid structure. This is the tile object
 * that holds every in-game entity present on a tile.
 */
//TODO write tests
class GridTile(implicit override val bindingModule: BindingModule) extends Node with Tile {
  private var tileContent = Set[EntityRef]()
  
  override def content = tileContent.toList
  
  override def addEntity(entity: EntityRef): Boolean = {
    if (tileContent contains entity) {
      false
    } else {
      tileContent += entity
      true
    }
  }
  
  override def removeEntity(entity: EntityRef): Boolean = {
    if (tileContent contains entity) {
      tileContent -= entity
      true
    } else {
      false
    }
  }
  
  override def copy: GridTile = {
    val cpy = new GridTile()
    cpy.x = this.x
    cpy.y = this.y
    val content = this.content.map(_.copy)
    for (entity <- content) {
      cpy.addEntity(entity)
    }
    
    cpy
  }
}